package com.example.accessibilityhelper.group

import android.accessibilityservice.AccessibilityService
import android.view.accessibility.AccessibilityEvent
import com.example.accessibilityhelper.Step
import com.example.accessibilityhelper.WeChatHelperService
import com.example.accessibilityhelper.util.click
import com.example.accessibilityhelper.util.findAccessibilityNodeByShortViewId
import com.example.accessibilityhelper.util.isWindowStateChanged

class Step0SwitchToWorkTab : Step() {

    override fun match(service: AccessibilityService, event: AccessibilityEvent): Boolean {
        return event.isWindowStateChanged()
                && event.className == WeChatHelperService.PAGE.MAIN_PAGE
    }

    override fun execute(service: AccessibilityService, event: AccessibilityEvent) {
//        val recyclerViewNode =
//            service.rootInActiveWindow.findAccessibilityNodeByShortViewId("s8")
//        recyclerViewNode.firstOrNull()?.getChild(1)?.click()
        service.rootInActiveWindow
            .findAccessibilityNodeByShortViewId("gsj")
            .firstOrNull()
            ?.getChild(2)
            ?.click()
        finish()
    }
}